#pragma once
#include "machine.h"
#include "cpu/dead6809/dead6809.h"
#include "cpu/dead6808/dead6808.h"
#include "apu/dac.h"
#include "6821.h"

#define F_NOWATCHDOG				1
#define F_MAYDAYPROTECTION		2		//flag for mayday

class CDefenderMachine:public CMachine
{
public:
	CDead6809 *MainCPU;					//6809 main cpu
	CDead6808 *SoundCPU;					//6808 sound cpu
	C6821 *PIA[3];							//pia's
	CDAC *DAC;								//dac for audio processing
protected:
	u8 MainROM[0x20000];					//main rom pages
	u8 SoundROM[0x10000];				//sound rom pages
	u8 PROM[0x400];						//prom data
	u8 VRAM[0x9800];						//vram
	u8 MainRAM[0x2800];					//ram
	u8 SoundRAM[0x100];					//sound ram
	u8 NVRAM[0x400];						//nvram
	u8 PaletteRAM[0x10];					//palette ram
	u32 Palette[0x10];					//converted palette
	u8 Screen[304 * (256 + 16)];		//screen drawn to
	u8 BankRegister;						//bank select register
	u8 *BankPointer;						//pointer to data referenced at $C000-$CFFF
	int Scanline;							//current scanline
	list_c SoundWrites;					//queue of sound writes
protected:
	void WritePalette(u32 addr,u8 data);
public:
	CDefenderMachine();
	virtual ~CDefenderMachine();
	virtual int Init();
	virtual void Kill();
	virtual void Reset();
	virtual void Blit();
	virtual void Line(u32 mainc,u32 soundc,int irq);
	virtual void Frame();
	virtual void SaveState(CState *s);
	virtual void LoadState(CState *s);
	virtual void RenderScreen(u8 *dest,int pitch);
	static void ProcessSound(void *user,void *data,int len);
	static u8 ReadMainCPU(void *user,u32 addr);
	static void WriteMainCPU(void *user,u32 addr,u8 data);
	static u8 ReadSoundCPU(void *user,u32 addr);
	static void WriteSoundCPU(void *user,u32 addr,u8 data);
	static u8 PIA0_InputA(void *user);
	static u8 PIA0_InputB(void *user);
	static u8 PIA1_InputA(void *user);
	static void PIA1_OutputB(void *user,u8 data);
	static void PIA1_IRQA(void *user);
	static void PIA1_IRQB(void *user);
	static void PIA2_OutputA(void *user,u8 data);
	static void PIA2_IRQA(void *user);
	static void PIA2_IRQB(void *user);
	
	int GetScanline(){return(Scanline);};
};
